package com.health.fragment.focusgroup.child;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.health.viewscontrols.FWMYDPJActivity;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.viewscontrols.focusgroup.ChildActivity;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.CHILD_ONE2THREE_YEAR_OLD;
import com.health.tablebean.CHILD_TCMHM_ONE2THREE;
import com.health.tools.DateUtil;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.widget.EditTextWithDate;
import com.health.widget.MyGridView;
import com.novabluetooth.services.BluetoothConstant;
import com.novabluetooth.views.ExamHistoryActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

/**
 * 1-2岁内检查 12月龄健康检查记录表
 *
 * @author 鹿云龙
 */
public class CheckFragment2_1 extends NovaFragment implements onFragmentSave, OnClickListener {
    private View baseView = null;
    // private CHILD_ONE2THREE_YEAR_OLD coyo;
    private ARCHIVE_BASEINFO userInfo;// 基本信息
    // CHILD_TCMHM_ONE2THREE
    private EditTextWithDate et_sfrq;
    private EditTextWithDate et_xcsfrq;
    /**
     * 未见异常
     */
    private List<BD_DD_INFO> lstyc;
    private EditText et_tz;
    private EditText et_sc;
    private EditText et_pf;
    private EditText et_qx1;
    private EditText et_qx2;
    private EditText et_cy;
    private EditText et_qc;
    private EditText et_fb;
    private EditText et_hwhd;
    private EditText et_fywssb;
    //	private EditText et_qt;
    private EditText et_zzyy;
    private NiceSpinner et_sfysqm;// 随访医生签名
    private EditText jgjks;

    /**
     * 面色
     */
    private MyGridView mgvmianse;
    /**
     * 前囟
     */
    private MyGridView mgvqianxin;
    /**
     * 眼外观
     */
    private MyGridView mgvyanwaiguan;
    /**
     * 听力
     */
    private MyGridView mgvtingli;
    /**
     * 心肺
     */
    private MyGridView mgvxinfei;

    // private MyGridView mgv_gangmen;
    /**
     * 皮肤
     */
    private MyGridView mgvpifu;
    // private MyGridView mgvjingbubaokuai;
    /**
     * 耳外观
     */
    private MyGridView mgverwaiguan;
    // private MyGridView mgvkouqiang;
    /**
     * 腹部
     */
    private MyGridView mgvfubu;
    /**
     * 四肢
     */
    private MyGridView mgvsizhi;

    // private NiceSpinner ns_kyglbzz;
    /**
     * 可疑佝偻病体征
     */
    private MyGridView mgv_kyglbtz;// mgv_kyglbtz
    // 发育评估
    /**
     * 发育评估
     */
    private MyGridView mgv_fayupinggu;
    /**
     * 两次随访间患病相关
     **/
    private MyGridView mgv_liangcisuifang;
    private EditText et_hbfy;
    private EditText et_hbfx;
    private EditText et_hbws;
    private EditText et_hbqt;

    /**
     * 指导mgv_zhidao
     */
    private MyGridView mgv_zhidao;
    // 转诊建议
    /**
     * 转诊建议
     */
    // private MyGridView mgv_zzjy;
    private MyGridView zhongyi;

    private static final Integer I_NULL = null;// -1
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    private RadioGroup rd_zz;// 是否转诊
    private RadioButton rb_w;
    private RadioButton rb_y;
    private String str_zzId = "";
    //
    // private void saveData() {
    //
    // CHILD_ONE2THREE_YEAR_OLD coyo = new CHILD_ONE2THREE_YEAR_OLD();
    // coyo.setIDCARD(userInfo.getIDCARD());
    // coyo.setAMONG_TWO_FOLLOWUP(rbalc.getChecked());// 两次患病随访
    // // coyo.setARCHIVEID(aRCHIVEID);//档案编号
    // // coyo.setAUXE_ESTIMATE(aUXE_ESTIMATE);//发育评估
    // coyo.setBREGMA(rbaqx.getChecked());
    // String strQx1 = et_qx1.getText().toString();
    // strQx1.isEmpty();
    // // if (!strQx1.isEmpty()) {
    // coyo.setBREGMA_LEFT(strQx1);
    // // }
    // String strQx2 = et_qx2.getText().toString();
    // // if (!strQx2.isEmpty()) {
    // coyo.setBREGMA_RIGHT(strQx2);
    // // }
    // coyo.setCOLOUR_FACE(rbamianse.getChecked());
    // coyo.setLISTENING(rbatl.getChecked());// 听力
    // coyo.setAUXE_ESTIMATE(rbafy.getChecked());
    // // coyo.setCREATED_BY(cREATED_BY);//创建人
    // //
    // coyo.setCREATED_DATE(new Date());
    // // coyo.setCUSTOMERID(cUSTOMERID);//客户编号
    // coyo.setEAR_APPEARANCE(rbaewg.getChecked());
    // coyo.setEYE_APPEARANCE(rbaywg.getChecked());
    // coyo.setFLAG("1");
    // coyo.setFOLLOWUP_DOCTOR_SIGN(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
    // coyo.setFOUR_LIMB(rbasz.getChecked());
    // // coyo.setGAIT(gAIT);
    // coyo.setGUIDANCE(cbazhidao.getCheckedIdsStr());
    // coyo.setGUIDANCE_OTHER(cbazhidao.getOther());
    // coyo.setHEART_LUNG(rbaxf.getChecked());
    // // coyo.setHEMOGLOBIN_VALUE(etx);//12月没有血红蛋白
    // // coyo.setLAST_UPDATE_BY(1);
    // coyo.setLAST_UPDATE_DATE(new Date());
    // coyo.setNAME(userInfo.getCUSTOMERNAME());
    // try {
    // coyo.setNEXT_FOLLOWUP_DATE(sdf.parse(et_xcsfrq.getText().toString()));
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    // coyo.setOTHER(et_qt.getText().toString());
    // String strHwhd = et_hwhd.getText().toString();
    // // if (!strHwhd.isEmpty()) {
    // coyo.setOUTDOOR_ACTIVITIES(strHwhd);
    // }

    // private EditText zyqt;
    private int zyfrom;

    private int from;
    private NiceSpinner ns_tz;

    private Button btn_tz_more;

    private EditText zyqt;
    List<EditText> lstTv;

    @Override
    public View findViews(LayoutInflater inflater) {
        baseView = inflater.inflate(R.layout.child_check_fragment2_1, null);
        userInfo = NovaApplication.getUserInfo();

        mgvmianse = (MyGridView) baseView.findViewById(R.id.mgvmianse);
        mgvqianxin = (MyGridView) baseView.findViewById(R.id.mgvqianlu);
        mgvyanwaiguan = (MyGridView) baseView.findViewById(R.id.mgvyanwaiguan);
        mgvtingli = (MyGridView) baseView.findViewById(R.id.mgvtingli);
        mgvxinfei = (MyGridView) baseView.findViewById(R.id.mgvxinfei);
        // mgvqibu = (MyGridView) baseView.findViewById(R.id.mgvqibu);

        // mgv_gangmen = (MyGridView) baseView.findViewById(R.id.mgv_gangmen);
        mgvpifu = (MyGridView) baseView.findViewById(R.id.mgvpifu);
        // mgvjingbubaokuai = (MyGridView)
        // baseView.findViewById(R.id.mgvjingbubaokuai);
        mgverwaiguan = (MyGridView) baseView.findViewById(R.id.mgverwaiguan);
        // mgvkouqiang = (MyGridView) baseView.findViewById(R.id.mgvkouqiang);
        mgvfubu = (MyGridView) baseView.findViewById(R.id.mgvfubu);
        mgvsizhi = (MyGridView) baseView.findViewById(R.id.mgvsizhi);
        // ns_kyglbzz = (NiceSpinner) baseView.findViewById(R.id.ns_kyglbzz);
        mgv_kyglbtz = (MyGridView) baseView.findViewById(R.id.mgv_kyglbtz);
        mgv_fayupinggu = (MyGridView) baseView.findViewById(R.id.mgv_fayupinggu);
        mgv_liangcisuifang = (MyGridView) baseView.findViewById(R.id.mgv_liangcisuifang);
        mgv_zhidao = (MyGridView) baseView.findViewById(R.id.mgv_zhidao);
        // mgv_zzjy = (MyGridView) baseView.findViewById(R.id.mgv_zzjy);
        zhongyi = (MyGridView) baseView.findViewById(R.id.zhongyi);
        ns_sg = (NiceSpinner) baseView.findViewById(R.id.ns_sg);
        ns_tz = (NiceSpinner) baseView.findViewById(R.id.ns_tz);
        // mgv_fayupinggu
        // initData();

        et_tz = (EditText) baseView.findViewById(R.id.et_tz);
        et_sc = (EditText) baseView.findViewById(R.id.et_sc);
        et_pf = (EditText) baseView.findViewById(R.id.et_pf);
        et_qx1 = (EditText) baseView.findViewById(R.id.et_qx1);
        et_qx2 = (EditText) baseView.findViewById(R.id.et_qx2);
        et_cy = (EditText) baseView.findViewById(R.id.et_cy);
        et_qc = (EditText) baseView.findViewById(R.id.et_qc);
        et_fb = (EditText) baseView.findViewById(R.id.et_fb);
        et_hwhd = (EditText) baseView.findViewById(R.id.et_hwhd);
        et_fywssb = (EditText) baseView.findViewById(R.id.et_fywssb);
//		et_qt = (EditText) baseView.findViewById(R.id.et_qt);
        et_zzyy = (EditText) baseView.findViewById(R.id.et_zzyy);
        et_sfysqm = (NiceSpinner) baseView.findViewById(R.id.et_sfysqm);
        GlobalConts.doctorList(et_sfysqm);
        zyqt = (EditText) baseView.findViewById(R.id.et_zyqt);
        jgjks = (EditText) baseView.findViewById(R.id.jgjks);
        et_sfrq = (EditTextWithDate) baseView.findViewById(R.id.etw_sfrq);
        et_xcsfrq = (EditTextWithDate) baseView.findViewById(R.id.et_xcsfrq);
        et_sfrq.setBefore(true);
        et_xcsfrq.setAfter(true);

        et_hbfy = (EditText) baseView.findViewById(R.id.et_hbfy);
        et_hbfx = (EditText) baseView.findViewById(R.id.et_hbfx);
        et_hbws = (EditText) baseView.findViewById(R.id.et_hbws);
        et_hbqt = (EditText) baseView.findViewById(R.id.et_hbqt);

        rd_zz = (RadioGroup) baseView.findViewById(R.id.rd_zz);
        rb_w = (RadioButton) baseView.findViewById(R.id.rb_w);
        rb_y = (RadioButton) baseView.findViewById(R.id.rb_y);
        et_zzyy.setEnabled(false);
        jgjks.setEnabled(false);

        GlobalConts.setMaxLength(2, et_cy, et_qc, et_hwhd);
        GlobalConts.setMaxLength(50, et_pf, et_fb, et_zzyy, et_pf, jgjks);
        GlobalConts.setMaxLength(5, et_fywssb, et_tz, et_sc, et_qx1, et_qx2);
        GlobalConts.keep2decimal(et_tz, et_sc, et_fywssb, et_qx1, et_qx2);
        GlobalConts.setMaxLength(100, et_hbqt);
        setupView(baseView);
        bind();
        initData();
        return baseView;
    }

    public void initData() {
        try {
            et_sfrq.setText(sdf.format(new Date(System.currentTimeMillis())));
            CHILD_ONE2THREE_YEAR_OLD coyo = new CHILD_ONE2THREE_YEAR_OLD();

            List<CHILD_ONE2THREE_YEAR_OLD> coyos = FDbManager.getInstance(getActivity()).findAllByWhere(
                    CHILD_ONE2THREE_YEAR_OLD.class, "IDCARD = '" + userInfo.getIDCARD() + "' AND FLAG='1'");
            et_sfrq.setText(sdf.format(new Date()));
            if (coyos.size() > 0) {

                from = 1;
                coyo = coyos.get(coyos.size() - 1);

                rbalc.setChecked(coyo.getAMONG_TWO_FOLLOWUP());// 两次患病随访

                if ("DM01-11_2".equals(coyo.getAMONG_TWO_FOLLOWUP())) {
                    for (int i = 0; i < lstTv.size(); i++) {
                        lstTv.get(i).setEnabled(true);
                        lstTv.get(i).setFocusable(true);
                        lstTv.get(i).setFocusableInTouchMode(true);
                        lstTv.get(i).setClickable(true);
                    }
                } else if ("DM01-11_1".equals(coyo.getAMONG_TWO_FOLLOWUP())) {
                    for (int i = 0; i < lstTv.size(); i++) {
                        lstTv.get(i).setEnabled(false);
                        lstTv.get(i).setFocusable(false);
                        lstTv.get(i).setFocusableInTouchMode(false);
                        lstTv.get(i).setClickable(false);
                    }
                }


                // coyo.getARCHIVEID(aRCHIVEID);//档案编号
                // coyo.getAUXE_ESTIMATE(aUXE_ESTIMATE);//发育评估
                rbaqx.setChecked(coyo.getBREGMA());// rbaqx.getChecked());
                // String strQx1 = et_qx1.getText().toString();
                et_qx1.setText(coyo.getBREGMA_LEFT());// strQx1.isEmpty()
                et_qx2.setText(coyo.getBREGMA_RIGHT());// strQx2.isEmpty()
                rbamianse.setChecked(coyo.getCOLOUR_FACE());// rbamianse.getChecked());
                rbatl.setChecked(coyo.getLISTENING());// 听力
                rbafy.setChecked(coyo.getAUXE_ESTIMATE_OTHER());// 发育评估
                // coyo.getCREATED_BY(cREATED_BY);//创建人

                // coyo.getCUSTOMERID(cUSTOMERID);//客户编号
                rbaewg.setChecked(coyo.getEAR_APPEARANCE());// rbaewg.getChecked());
                rbaywg.setChecked(coyo.getEYE_APPEARANCE());// rbaywg.getChecked());
                // coyo.getFLAG("1");
                // coyo.getFOLLOWUP_Date(new Date());
                // coyo.getFOLLOWUP_DOCTOR_SIGN(et_sfysqm.getText().toString());
                rbasz.setChecked(coyo.getFOUR_LIMB());// rbasz.getChecked());
                // coyo.getGAIT(gAIT);
                cbazhidao.setChecked(coyo.getGUIDANCE());// cbazhidao.getCheckedIdsStr());
                cbazhidao.setOther(coyo.getGUIDANCE_OTHER());// cbazhidao.getOther());
                rbaxf.setChecked(coyo.getHEART_LUNG());// rbaxf.getChecked());
                // coyo.getHEMOGLOBIN_VALUE(etx);//12月没有血红蛋白
                // coyo.getLAST_UPDATE_BY(1);
                // coyo.getLAST_UPDATE_DATE(new Date());
                // coyo.getNAME(userInfo.getCUSTOMERNAME());

                // 两次随访患者
                et_hbfy.setText(coyo.getPNEUMONIA_FREQUEN());
                et_hbfx.setText(coyo.getDIARRHOEA_FREQUEN());// strff.isEmpty()
                et_hbws.setText(coyo.getTRAUMATISM_FREQUEN());
                et_hbqt.setText(coyo.getAMONG_TWO_FOLLO_OTHER());

                try {
                    et_xcsfrq.setText(sdf.format(coyo.getNEXT_FOLLOWUP_DATE()));// sdf.parse(et_xcsfrq.getText().toString()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
//				et_qt.setText(coyo.getOTHER());// et_qt.getText().toString());
                String strHwhd = et_hwhd.getText().toString();
                et_hwhd.setText(coyo.getOUTDOOR_ACTIVITIES());// strHwhd.isEmpty()

                str_zzId = coyo.getREFERRAL_ADVICE();

                if (!TextUtils.isEmpty(str_zzId)) {
                    if (str_zzId.equals("DM01-11_1")) {
                        rb_w.setChecked(true);
                    } else if (str_zzId.equals("DM01-11_2")) {
                        rb_y.setChecked(true);
                    }
                }

                // adapter_zz.setChecked(str_zzId);

                et_zzyy.setText(coyo.getREFERRAL_REASON());
                jgjks.setText(coyo.getAGENCIES_DEPARTMENTS());// jgjks.getText().toString());

                et_sc.setText(coyo.getSTATURE());// strSc.isEmpty()
                rbapf.setChecked(coyo.getSKIN());// rbapf.getChecked());
                ns_sg.setSelectedIndex(getListIndex(coyo.getSTATURE_ANALYSIS(), lst_sg));// lst_sg.get(ns_sg.getSelectedIndex()).getID());
                rbafb.setChecked(coyo.getSTOMACH());// rbafb.getChecked());
                rbaglbtz.setChecked(coyo.getSUSPICIOUS_RICKETS());// .get(ns_kyglbtz.getSelectedIndex()).getID());
                et_fywssb.setText(coyo.getTAKING_VITAMINSD());// strD.isEmpty()
                et_cy.setText(coyo.getTEETH_DCN_LEFT());// strCy.isEmpty()
                et_qc.setText(coyo.getTEETH_DCN_RIGHT());// strQc.isEmpty()
                et_tz.setText(coyo.getWEIGHT());// strTz.isEmpty()
                ns_tz.setSelectedIndex(getListIndex(coyo.getWEIGHT_ANALYSIS(), lst_sg));// get(ns_tz.getSelectedIndex()).getID());
                // et_sfrq.setText(sdf.format(coyo.getFOLLOWUP_DATE()));
                // et_sfrq.setText(sdf.format(new Date()));
                for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
                    if (coyo.getFOLLOWUP_DOCTOR_SIGN().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
                        et_sfysqm.setSelectedIndex(i);
                    }
                }
            } else {
                // et_sfrq.setText(sdf.format(new Date()));
                for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
                    if (userInfo.getCREATED_BY().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
                        et_sfysqm.setSelectedIndex(i);
                    }
                }
            }
            // TODO 中医药

            List<CHILD_TCMHM_ONE2THREE> ctos = FDbManager.getInstance(getActivity()).findAllByWhere(
                    CHILD_TCMHM_ONE2THREE.class, "IDCARD = '" + userInfo.getIDCARD() + "' AND FOLLOWUP_TYPE='1'");
            if (ctos.size() > 0) {
                CHILD_TCMHM_ONE2THREE cto = ctos.get(ctos.size() - 1);
                cbazy.setOther(cto.getTCMHM_OTHER());// zyqt.getText().toString());
                cbazy.setChecked(cto.getTCMHM());// .getCheckedIdsStr());
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    RadioButtonAdapter rbamianse;
    RadioButtonAdapter rbaqx;
    RadioButtonAdapter rbaywg;
    RadioButtonAdapter rbatl;
    RadioButtonAdapter rbaxf;
    RadioButtonAdapter rbapf;
    RadioButtonAdapter rbaewg;
    RadioButtonAdapter rbafb;
    RadioButtonAdapter rbasz;
    CheckBoxAdapter rbafy;
    RadioButtonAdapter rbalc;
    CheckBoxAdapter cbazhidao;
    // RadioButtonAdapter rbazz;
    CheckBoxAdapter cbazy;
    RadioButtonAdapter rbaglbtz;
    NiceSpinner ns_sg;
    List<BD_DD_INFO> lst_sg;
    List<BD_DD_INFO> lstkyglbtz;

    public void bind() {
        /*获取异常和未见异常值*/
        lstyc = GlobalConts.getDictionaryValue(getActivity(), "DM01-40");

        GlobalConts.checkNumOrange(getActivity(), et_cy, 32, 0);
        GlobalConts.checkNumOrange(getActivity(), et_qc, 32, 0);
        // 体重
        // 身高DM01-39
        lst_sg = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
                "PARENTID = 'DM01-39' order by cast(SORT as int) asc");
        ns_sg.attachDataSource(getDataInfo(lst_sg));
        ns_tz.attachDataSource(getDataInfo(lst_sg));
        // 面色DM05-14_1
        List<BD_DD_INFO> lstms = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
                "PARENTID = 'DM05-14_2' order by cast(SORT as int) asc");
        rbamianse = new RadioButtonAdapter(lstms, getActivity());
        rbamianse.setOtherTextVisible(false);
        mgvmianse.setAdapter(rbamianse);
        // 前囟DM05-16_1
        List<BD_DD_INFO> lstqx = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
                "PARENTID = 'DM05-16_1' order by cast(SORT as int) asc");
        rbaqx = new RadioButtonAdapter(lstqx, getActivity());
        rbaqx.setOtherTextVisible(false);
        mgvqianxin.setAdapter(rbaqx);
        /* 眼外观lstyc*/
        rbaywg = new RadioButtonAdapter(lstyc, getActivity());
        rbaywg.setOtherTextVisible(false);
        mgvyanwaiguan.setAdapter(rbaywg);
        /*听力DM01-30*/
        List<BD_DD_INFO> lsttl = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
                "PARENTID = 'DM01-30' order by cast(SORT as int) asc");
        rbatl = new RadioButtonAdapter(lsttl, getActivity());
        rbatl.setOtherTextVisible(false);
        mgvtingli.setAdapter(rbatl);
        // 心肺lstyc
        rbaxf = new RadioButtonAdapter(lstyc, getActivity());
        rbaxf.setOtherTextVisible(false);
        mgvxinfei.setAdapter(rbaxf);
        // 脐部lstyc
        // RadioButtonAdapter rbaqb = new RadioButtonAdapter(lstyc,
        // getActivity());
        // rbaqb.setOtherTextVisible(false);
        // mgvqibu.setAdapter(rbaqb);
        // 肛门/外生殖lstyc
        // RadioButtonAdapter rbagm = new RadioButtonAdapter(lstyc,
        // getActivity());
        // rbagm.setOtherTextVisible(false);
        // mgv_gangmen.setAdapter(rbagm);
        // mgvpifu
        rbapf = new RadioButtonAdapter(lstyc, getActivity());
        rbapf.setOtherTextVisible(false);
        mgvpifu.setAdapter(rbapf);
        // 颈部包块lstyw
        // RadioButtonAdapter rbajbbk = new RadioButtonAdapter(lstyw,
        // getActivity());
        // rbajbbk.setOtherTextVisible(false);
        // mgvjingbubaokuai.setAdapter(rbajbbk);
        // 耳外观
        rbaewg = new RadioButtonAdapter(lstyc, getActivity());
        rbaewg.setOtherTextVisible(false);
        mgverwaiguan.setAdapter(rbaewg);
        // 口腔
        // RadioButtonAdapter rbakq = new RadioButtonAdapter(lstyc,
        // getActivity());
        // rbakq.setOtherTextVisible(false);
        // mgvkouqiang.setAdapter(rbakq);
        // 腹部
        rbafb = new RadioButtonAdapter(lstyc, getActivity());
        rbafb.setOtherTextVisible(false);
        mgvfubu.setAdapter(rbafb);
        // 四肢
        rbasz = new RadioButtonAdapter(lstyc, getActivity());
        rbasz.setOtherTextVisible(false);
        mgvsizhi.setAdapter(rbasz);
        // 可疑佝偻病症状DM05-21
        // List<BD_DD_INFO> lstkyglbzz =
        // FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
        // "PARENTID = 'DM05-21' order by cast(SORT as int) asc");
        // ns_kyglbzz.attachDataSource(getDataInfo(lstkyglbzz));
        // 可疑佝偻病体征DM05-19_2
        lstkyglbtz = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
                "PARENTID = 'DM05-19_3' order by cast(SORT as int) asc");
        List<BD_DD_INFO> lstkyglbtz_new = new ArrayList<BD_DD_INFO>();
        int size2 = lstkyglbtz.size();
        if (size2 > 0) {
            for (int i = 0; i < size2; i++) {

                // DM05-19_3_1 1 正常、DM05-19_3_2 O型腿
                // DM05-19_3_3 X型腿
                // if (lstkyglbtz.get(i).getID().equals("DM05-19_3_2")
                // || lstkyglbtz.get(i).getID().equals("DM05-19_3_3")
                // || lstkyglbtz.get(i).getID().equals("DM05-19_3_3")) {
                lstkyglbtz_new.add(lstkyglbtz.get(i));
                // }
            }
        }

        rbaglbtz = new RadioButtonAdapter(lstkyglbtz_new, getActivity());
        mgv_kyglbtz.setAdapter(rbaglbtz);
        // 发育评估 DM01-30
        List<BD_DD_INFO> lstfy = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
                "PARENTID = 'DM05-26_4' order by cast(SORT as int) asc");
        rbafy = new CheckBoxAdapter(getActivity(), lstfy);
        rbafy.setOtherVis(false);
        mgv_fayupinggu.setAdapter(rbafy);
        // 两次随访DM05-20
        List<BD_DD_INFO> lstlc = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
                "PARENTID = 'DM01-11' order by cast(SORT as int) asc");
        lstTv = new ArrayList<EditText>();
        lstTv.add(et_hbfy);
        lstTv.add(et_hbfx);
        lstTv.add(et_hbws);
        lstTv.add(et_hbqt);
        rbalc = new RadioButtonAdapter(lstlc, getActivity(), lstTv);
        rbalc.setOtherTextVisible(false);
        mgv_liangcisuifang.setAdapter(rbalc);

        // 健康指导
        List<BD_DD_INFO> lstzd = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
                "PARENTID = 'DM05-04' order by cast(SORT as int) asc");

        List<BD_DD_INFO> listZZs_new_zd = new ArrayList<BD_DD_INFO>();
        int size_zd = lstzd.size();
        if (size_zd > 0) {
            for (int i = 0; i < size_zd; i++) {

                // DM05-04_1 科学喂养 ；DM05-04_2 合理膳食 ；DM05-04_3 生长发育
                // DM05-04_4 疾病预防;DM05-04_5 预防意外伤害;DM05-04_6 口腔保健
                // DM05-04_9 其他
                if (lstzd.get(i).getID().equals("DM05-04_1") || lstzd.get(i).getID().equals("DM05-04_3")
                        || lstzd.get(i).getID().equals("DM05-04_4") || lstzd.get(i).getID().equals("DM05-04_5")
                        || lstzd.get(i).getID().equals("DM05-04_6") || lstzd.get(i).getID().equals("DM05-04_9")) {
                    listZZs_new_zd.add(lstzd.get(i));
                }
            }
        }

        cbazhidao = new CheckBoxAdapter(getActivity(), listZZs_new_zd);
        mgv_zhidao.setAdapter(cbazhidao);
        // // 转诊建议
        // rbazz = new RadioButtonAdapter(lstyw, getActivity());
        // mgv_zzjy.setAdapter(rbazz);
        /*中医DM200-04*/
        List<BD_DD_INFO> listZZs_new = new ArrayList<BD_DD_INFO>();
        List<BD_DD_INFO> listZZs = GlobalConts.getDictionaryValue(getActivity(), "DM200-04");
        if (listZZs.size() > 0) {
            for (BD_DD_INFO item : listZZs) {
                /**
                 * DM200-04_1：中医饮食调养指导
                 * DM200-04_2：中医起居调摄指导
                 * DM200-04_3：传授摩腹、捏脊方法
                 * DM200-04_0：其他
                 */
                switch (item.getID()) {
                    case "DM200-04_0":
                    case "DM200-04_1":
                    case "DM200-04_2":
                    case "DM200-04_3":
                        listZZs_new.add(item);
                        break;
                    default:
                }
            }
        }
        cbazy = new CheckBoxAdapter(getActivity(), listZZs_new);
        zhongyi.setAdapter(cbazy);
    }

    /**
     * 获取下拉框中需要的数据的信息
     *
     * @param datas
     * @return
     * @author 鹿云龙
     * @date 2015年12月16日 下午3:47:00
     */
    private ArrayList<String> getDataInfo(List<BD_DD_INFO> datas) {
        ArrayList<String> infos = new ArrayList<String>();
        for (BD_DD_INFO bd : datas) {
            infos.add(bd.getDATAINFO());
        }
        return infos;
    }

    @Override
    public void setupView(View view) {
        mgvmianse = (MyGridView) baseView.findViewById(R.id.mgvmianse);
        mgvqianxin = (MyGridView) baseView.findViewById(R.id.mgvqianlu);
        mgvyanwaiguan = (MyGridView) baseView.findViewById(R.id.mgvyanwaiguan);
        mgvtingli = (MyGridView) baseView.findViewById(R.id.mgvtingli);
        mgvxinfei = (MyGridView) baseView.findViewById(R.id.mgvxinfei);
        // mgvqibu = (MyGridView) baseView.findViewById(R.id.mgvqibu);

        // mgv_gangmen = (MyGridView) baseView.findViewById(R.id.mgv_gangmen);
        mgvpifu = (MyGridView) baseView.findViewById(R.id.mgvpifu);
        // mgvjingbubaokuai = (MyGridView)
        // baseView.findViewById(R.id.mgvjingbubaokuai);
        mgverwaiguan = (MyGridView) baseView.findViewById(R.id.mgverwaiguan);
        // mgvkouqiang = (MyGridView) baseView.findViewById(R.id.mgvkouqiang);
        mgvfubu = (MyGridView) baseView.findViewById(R.id.mgvfubu);
        mgvsizhi = (MyGridView) baseView.findViewById(R.id.mgvsizhi);
        // ns_kyglbzz = (NiceSpinner) baseView.findViewById(R.id.ns_kyglbzz);
        mgv_kyglbtz = (MyGridView) baseView.findViewById(R.id.mgv_kyglbtz);
        mgv_fayupinggu = (MyGridView) baseView.findViewById(R.id.mgv_fayupinggu);
        mgv_liangcisuifang = (MyGridView) baseView.findViewById(R.id.mgv_liangcisuifang);
        mgv_zhidao = (MyGridView) baseView.findViewById(R.id.mgv_zhidao);
        // mgv_zzjy = (MyGridView) baseView.findViewById(R.id.mgv_zzjy);
        zhongyi = (MyGridView) baseView.findViewById(R.id.zhongyi);
        ns_sg = (NiceSpinner) baseView.findViewById(R.id.ns_sg);
        ns_tz = (NiceSpinner) baseView.findViewById(R.id.ns_tz);
        // mgv_fayupinggu
        // initData();

        et_tz = (EditText) baseView.findViewById(R.id.et_tz);
        et_sc = (EditText) baseView.findViewById(R.id.et_sc);
        et_pf = (EditText) baseView.findViewById(R.id.et_pf);
        et_qx1 = (EditText) baseView.findViewById(R.id.et_qx1);
        et_qx2 = (EditText) baseView.findViewById(R.id.et_qx2);
        et_cy = (EditText) baseView.findViewById(R.id.et_cy);
        et_qc = (EditText) baseView.findViewById(R.id.et_qc);
        et_fb = (EditText) baseView.findViewById(R.id.et_fb);
        et_hwhd = (EditText) baseView.findViewById(R.id.et_hwhd);
        et_fywssb = (EditText) baseView.findViewById(R.id.et_fywssb);
//		et_qt = (EditText) baseView.findViewById(R.id.et_qt);
        et_zzyy = (EditText) baseView.findViewById(R.id.et_zzyy);
        et_sfysqm = (NiceSpinner) baseView.findViewById(R.id.et_sfysqm);
        GlobalConts.doctorList(et_sfysqm);
        zyqt = (EditText) baseView.findViewById(R.id.et_zyqt);
        jgjks = (EditText) baseView.findViewById(R.id.jgjks);
        et_sfrq = (EditTextWithDate) baseView.findViewById(R.id.etw_sfrq);
        et_xcsfrq = (EditTextWithDate) baseView.findViewById(R.id.et_xcsfrq);
        et_sfrq.setBefore(true);
        et_xcsfrq.setAfter(true);

        rd_zz = (RadioGroup) baseView.findViewById(R.id.rd_zz);
        rb_w = (RadioButton) baseView.findViewById(R.id.rb_w);
        rb_y = (RadioButton) baseView.findViewById(R.id.rb_y);
        et_zzyy.setEnabled(false);
        jgjks.setEnabled(false);
        btn_tz_more = (Button) baseView.findViewById(R.id.btn_tz_more);
        btn_tz_more.setOnClickListener(this);

    }

    @Override
    public void addListener() {
        rd_zz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb_w) {
                    str_zzId = "DM01-11_1";
                    et_zzyy.setText("");
                    et_zzyy.setEnabled(false);
                    jgjks.setText("");
                    jgjks.setEnabled(false);

                } else if (checkedId == R.id.rb_y) {
                    str_zzId = "DM01-11_2";
                    et_zzyy.setEnabled(true);
                    jgjks.setEnabled(true);
                } else {
                    str_zzId = "";
                }

            }
        });
    }

    @Override
    public void setData() {

        // 肺炎
        GlobalConts.checkNumOrange(getActivity(), et_hbfy, 99, 0);
        // 腹泻
        GlobalConts.checkNumOrange(getActivity(), et_hbfx, 99, 0);
        // 外伤
        GlobalConts.checkNumOrange(getActivity(), et_hbws, 99, 0);
    }

    public int getListIndex(String id, List<BD_DD_INFO> bds) {
        int index = 0;
        try {
            for (int i = 0; i < bds.size(); i++) {
                if (id.equals(bds.get(i).getID())) {
                    index = i;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return index;
    }

    /**
     * 字符串转换"1,2,3,4,5" --> "'1','2','3','4','5'"
     *
     * @param symptom
     * @return
     * @author 鹿云龙
     * @date 2015年12月19日 下午2:49:23
     */
    public String checkedIdsSql(String symptom) {
        String[] idarr = symptom.split(",");
        String sql = "";
        for (String id : idarr) {
            sql += "'" + id + "',";
        }
        sql = sql.substring(0, sql.length() - 1);
        System.out.println(sql);
        return sql;
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    private void saveData() {

        String strCy = et_cy.getText().toString();
        if (!TextUtils.isEmpty(strCy)) {
            if (Integer.parseInt(strCy) > 32) {
                ((ChildActivity) getActivity()).showTextDialog("出牙/(龋齿数)最大值为32");
                return;
            }
        }
        String strQc = et_qc.getText().toString();
        if (!TextUtils.isEmpty(strQc)) {
            if (Integer.parseInt(strQc) > 32) {
                ((ChildActivity) getActivity()).showTextDialog("出牙/(龋齿数)最大值为32");
                return;
            }
        }
        if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_hbfy, 99, 0)) {
            ((ChildActivity) getActivity()).showTextDialog("肺炎数据不合理，保存失败");
            return;
        }
        if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_hbfx, 99, 0)) {
            ((ChildActivity) getActivity()).showTextDialog("腹泻数据不合理，保存失败");
            return;
        }
        if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_hbws, 99, 0)) {
            ((ChildActivity) getActivity()).showTextDialog("外伤不合理，保存失败");
            return;
        }

        CHILD_ONE2THREE_YEAR_OLD coyo = new CHILD_ONE2THREE_YEAR_OLD();
        coyo.setIDCARD(userInfo.getIDCARD());
        coyo.setAMONG_TWO_FOLLOWUP(rbalc.getChecked());// 两次患病随访
        // coyo.setARCHIVEID(aRCHIVEID);//档案编号
        // coyo.setAUXE_ESTIMATE(aUXE_ESTIMATE);//发育评估
        coyo.setBREGMA(rbaqx.getChecked());
        String strQx1 = et_qx1.getText().toString();
        strQx1.isEmpty();
        // if (!strQx1.isEmpty()) {
        coyo.setBREGMA_LEFT(strQx1);
        // }
        String strQx2 = et_qx2.getText().toString();
        // if (!strQx2.isEmpty()) {
        coyo.setBREGMA_RIGHT(strQx2);
        // }
        coyo.setCOLOUR_FACE(rbamianse.getChecked());
        coyo.setLISTENING(rbatl.getChecked());// 听力
        coyo.setAUXE_ESTIMATE_OTHER(rbafy.getCheckedIdsStr());
        // coyo.setCREATED_BY(cREATED_BY);//创建人
        //
        coyo.setCREATED_DATE(new Date());
        // coyo.setCUSTOMERID(cUSTOMERID);//客户编号
        coyo.setEAR_APPEARANCE(rbaewg.getChecked());
        coyo.setEYE_APPEARANCE(rbaywg.getChecked());
        coyo.setFLAG("1");
        coyo.setFOLLOWUP_DOCTOR_SIGN(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
        coyo.setFOUR_LIMB(rbasz.getChecked());
        // coyo.setGAIT(gAIT);
        coyo.setGUIDANCE(cbazhidao.getCheckedIdsStr());
        coyo.setGUIDANCE_OTHER(cbazhidao.getOther());
        coyo.setHEART_LUNG(rbaxf.getChecked());
        // coyo.setHEMOGLOBIN_VALUE(etx);//12月没有血红蛋白
        // coyo.setLAST_UPDATE_BY(1);
        coyo.setLAST_UPDATE_DATE(new Date());
        coyo.setNAME(userInfo.getCUSTOMERNAME());
        coyo.setIS_UPDATE("Y");
        // 两次随访
        String strfy = et_hbfy.getText().toString();
        coyo.setPNEUMONIA_FREQUEN(strfy);
        String strff = et_hbfx.getText().toString();
        coyo.setDIARRHOEA_FREQUEN(strff);
        String strws = et_hbws.getText().toString();
        coyo.setTRAUMATISM_FREQUEN(strws);
        coyo.setAMONG_TWO_FOLLO_OTHER(et_hbqt.getText().toString());

        try {
            coyo.setNEXT_FOLLOWUP_DATE(sdf.parse(et_xcsfrq.getText().toString()));
        } catch (Exception e) {
            e.printStackTrace();
        }
//		coyo.setOTHER(et_qt.getText().toString());
        String strHwhd = et_hwhd.getText().toString();
        // if (!strHwhd.isEmpty()) {
        coyo.setOUTDOOR_ACTIVITIES(strHwhd);
        // }

        if (rb_w.isChecked()) {
            str_zzId = "DM01-11_1";
        } else if (rb_y.isChecked()) {
            str_zzId = "DM01-11_2";
        } else {
            str_zzId = "";
        }

        coyo.setREFERRAL_ADVICE(str_zzId);
        coyo.setREFERRAL_REASON(et_zzyy.getText().toString());
        coyo.setAGENCIES_DEPARTMENTS(jgjks.getText().toString());
        String strSc = et_sc.getText().toString();
        // if (!strSc.isEmpty()) {
        coyo.setSTATURE(strSc);
        // }
        coyo.setSKIN(rbapf.getChecked());
        coyo.setSTATURE_ANALYSIS(lst_sg.get(ns_sg.getSelectedIndex()).getID());
        coyo.setSTOMACH(rbafb.getChecked());
        coyo.setSUSPICIOUS_RICKETS(rbaglbtz.getChecked());
        String strD = et_fywssb.getText().toString();
        // if (!strD.isEmpty()) {
        coyo.setTAKING_VITAMINSD(strD);
        // }
        // if (!strCy.isEmpty()) {
        coyo.setTEETH_DCN_LEFT(strCy);
        // }
        // if (!strQc.isEmpty()) {
        coyo.setTEETH_DCN_RIGHT(strQc);
        // }
        String strTz = et_tz.getText().toString();
        // if (!strTz.isEmpty()) {
        coyo.setWEIGHT(strTz);
        // }
        coyo.setWEIGHT_ANALYSIS(lst_sg.get(ns_tz.getSelectedIndex()).getID());
        try {
            if (!TextUtils.isEmpty(et_sfrq.getText().toString())) {
                coyo.setFOLLOWUP_DATE(sdf.parse(et_sfrq.getText().toString()));
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        coyo.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
        coyo.setLAST_UPDATE_DATE(new Date());
        if (from == 0) {
            coyo.setCREATED_BY(userInfo.getCREATED_BY());
            coyo.setCREATED_DATE(new Date());
            coyo.setCREATEORG(userInfo.getCREATEORG());
            coyo.setCREATER(userInfo.getCREATER());
            FDbManager.getInstance(getActivity()).save(coyo);
            from = 1;
        } else {

            coyo.setUPDATEORG(userInfo.getCREATEORG());
            coyo.setMODIFIED(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
            FDbManager.getInstance(getActivity()).updata(coyo, "IDCARD='" + userInfo.getIDCARD() + "' AND FLAG='1'");
        }
        // 中医药DM200-04
        // TODO cbazy
        CHILD_TCMHM_ONE2THREE cto = new CHILD_TCMHM_ONE2THREE();
        cto.setFOLLOWUP_TYPE("1");
        cto.setARCHIVEID("");
        cto.setIDCARD(userInfo.getIDCARD());
        cto.setTCMHM_OTHER(cbazy.getOther());
        cto.setTCMHM(cbazy.getCheckedIdsStr());

        cto.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
        cto.setLAST_UPDATE_DATE(new Date());
        if (zyfrom == 0) {
            cto.setCREATED_BY(userInfo.getCREATED_BY());
            cto.setCREATED_DATE(new Date());
            cto.setCREATEORG(userInfo.getCREATEORG());
            cto.setCREATER(userInfo.getCREATER());
            FDbManager.getInstance(getActivity()).save(cto);
            zyfrom = 1;
        } else {
            cto.setUPDATEORG(userInfo.getCREATEORG());
            cto.setMODIFIED(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
            FDbManager.getInstance(getActivity()).updata(cto,
                    "IDCARD='" + userInfo.getIDCARD() + "' AND FOLLOWUP_TYPE='1'");
        }
        // ((ChildActivity) getActivity()).showTextDialog("保存成功");
        if (GlobalConts.TYPE_JTYS.equals(NovaApplication.getType())) {
            new AlertDialog.Builder(getActivity()).setTitle("保存成功").setMessage("进行满意度评价")
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(getContext(), FWMYDPJActivity.class);
                            intent.putExtra("type", "02");
                            intent.putExtra("szfs", "");
                            startActivity(intent);
                        }
                    }).show();
        } else if (GlobalConts.TYPE_GJJBGGWS.equals(NovaApplication.getType())) {
            ((ChildActivity) getActivity()).showTextDialog("保存成功");
        }
    }

    // @Override
    // public void save() {
    // int months = DateUtil.getMonthsByDate(new Date(),
    // userInfo.getBIRTHDAY());
    // if (months != -1) {
    // if (months < 12) {
    // ((ChildActivity) getActivity()).showTextDialog("儿童未满12月龄，不予保存");
    // return;
    // }
    //
    // }
    // saveData();
    // }

    @Override
    public void save() {
        int months = DateUtil.getMonthsByDate(new Date(), userInfo.getBIRTHDAY());
        if (months != -1) {
            if (months < 12) {
                ((ChildActivity) getActivity()).showTextDialog("儿童未满12月龄，不予保存");
                return;
            }

        }
        saveData();
    }

    @Override
    public void setTizhong(String value) {
        et_tz.setText(value);

    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(getActivity(), ExamHistoryActivity.class);
        int id = v.getId();
        if (id == R.id.btn_tz_more) {
            intent.putExtra("flag", BluetoothConstant.TIZHONG_TYPENAME);
            getActivity().startActivityForResult(intent, GlobalConts.RequestTizhong);
        } else {
        }

    }
}